<template>
	<view class="container">
		<mescroll-body ref="mescrollRef" class="collection-list" @down="downCallback" :up="upOption" @up="getCollectList"
		 @init="mescrollInit" :fixed="true" :top="0">
			<view class="main-wrap" :class="{show:!isEmpty}">
				<view class="collection-item" v-for="(item,index) in collectionList" :key="index">
					<!-- 下架状态 -->
					<view class="item-con" v-if="item.productStatus==50">
						<view class="item-left">
							<image class="item-image" :src="imgSrc+item.productThumbnailImageUrl"></image>
							<view class="item-image-mask">
								<view class="mask-con">失效</view>
							</view>
						</view>
						<view class="item-right text-gray">
							<view class="item-name">{{item.productName}}</view>
							<view class="item-sales">累计销量：{{item.productSalesCount}}</view>
							<view class="item-discounts" v-if="item.activityName">
								<text class="discounts-type">{{item.activityName}}</text>
								<!-- <text class="discounts-detail ellipsis">{{item.discountsDetail}}</text> -->
							</view>
							<view class="item-price">￥{{item.productDiscountPrice}}</view>
						</view>
					</view>

					<view v-else class="item-con" @tap="goBuy(item)">
						<view class="item-left">
							<image class="item-image" :src="imgSrc+item.productThumbnailImageUrl"></image>
						</view>
						<view class="item-right">
							<view class="item-name">{{item.productName}}</view>
							<view class="item-sales">累计销量：{{item.productSalesCount}}</view>
							<view class="item-discounts" v-if="item.activityName">
								<text class="discounts-type">{{item.activityName}}</text>
								<!-- <text class="discounts-detail ellipsis">{{item.discountsDetail}}</text> -->
							</view>
							<view class="item-price">￥{{item.productDiscountPrice}}</view>
						</view>
					</view>
					<view class="item-btns">
						<tui-button v-if="item.productStatus==50" type="black" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle" disabled="true">购买</tui-button>
						<tui-button v-else type="danger" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle" @tap="goBuy(item)">购买</tui-button>
						<tui-button type="black" :plain="true" width="160rpx" height="62rpx" :size="28" shape="circle" @tap="cancelCollection(item)" style="margin-right: 10rpx;">取消收藏</tui-button>
					</view>
				</view>
			</view>
		</mescroll-body>
		<!-- 	<loading v-if="isLoading"></loading> -->
		<mix-empty v-if="isEmpty" :type="'favorite'" :backgroundColor="'#fff'"></mix-empty>
		<tui-modal></tui-modal>
	</view>
</template>

<script>
	import tuiButton from "@/components/button/button"
	import mixin from "@/utils/mixin.js"
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import mixEmpty from '@/components/mix-empty/mix-empty.vue'
	export default {
		mixins: [mixin, MescrollMixin],
		components: {
			tuiButton,
			mixEmpty
		},
		data() {
			return {
				imgSrc: this.$store.state.imgUrl,
				isEmpty: false,
				isLoading: false,
				collectionList: [],
				upOption: {
					auto: false, // 是否自动加载
					page: {
						size: 6
					},
					noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- 暂无更多信息 --'的提示
				},
			}
		},
		onLoad() {
			// #ifdef H5
			   this.$wechat.noShare();
			// #endif
		},

		methods: {
			getCollectList(page) {
				const params = {
					current: page.num,
					pageSize: page.size,
				};
				this.$http.getMyCollection(params).then((res) => {
					if (res.status === 0) {
						if (!res.data.records) {
							res.data.records = []
						}
						let curPageData = res.data.records;
						this.mescroll.endSuccess(res.data.records.length);
						if (page.num == 1) {
							this.collectionList = []
						};
						this.collectionList = this.collectionList.concat(curPageData);
						if (this.collectionList.length === 0) {
							this.isEmpty = true;
						} else {
							this.isEmpty = false;
						}
					}
				})
			},

			goBuy(item) {
				this.$util.gotoGoodsDetail('productId', item.productId);
			},
			cancelCollection(item) {
				this.isLoading = true;
				this.$http.cancelCollection(item.productId).then((res) => {
					this.isLoading = false;
					if (res.status === 0) {
						uni.showToast({
							title: "取消收藏成功!",
							icon: "none",
							duration: 500
						});
						this.getCollectList({
							size: 6,
							num: 1
						});
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.container{
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
	}
	.main-wrap {
		opacity: 0;
		transition: opacity .2s;
		// min-height: 100vh;
		padding-bottom: 18rpx;

		&.show {
			opacity: 1;
		}
	}

	.collection-list {
		.collection-item {
			position: relative;
			margin-top:16rpx;
			background-color: #fff;
		}

		.item-con {
			width: 100%;
			border-bottom: 1rpx solid #eee;
			display: flex;
			padding:30rpx 32rpx;

			.item-left {
				width: 200rpx;
				height: 200rpx;
				-webkit-border-radius: 16rpx;
				border-radius: 16rpx;
				-webkit-flex-shrink: 0;
				flex-shrink: 0;
				display: block;
				background: #D8D8D8;
				overflow: hidden;
				margin-right: 16rpx;
				position: relative;

				// margin: 0 20rpx;
				.item-image {
					width: 100%;
					height: 100%;
					// border:1rpx solid $borderColor;
					border-radius: 16rpx;
				}

				.item-image-mask {
					width: 100%;
					height: 100%;
					position: absolute;
					left: 0;
					top: 0;
					background: rgba(0, 0, 0, .3);
					display: flex;
					align-items: center;

					.mask-con {
						width: 100rpx;
						height: 100rpx;
						line-height: 100rpx;
						text-align: center;
						background: rgba(0, 0, 0, .3);
						margin: 0 auto;
						border-radius: 50%;
						color: #fff;
					}
				}
			}

			.item-right {
				flex: 1;
				position: relative;
				padding-top: 6rpx;
				width: calc(100% - 200rpx);

				.item-name {
					@include multiline-text-overflow;
					width: 100%;
					color: #444;
					font-size: 28rpx;
					line-height: 40rpx;
				}

				.item-sales {
					color: #aaa;
					font-size: 26rpx;
					margin: 6rpx 0;
				}

				.item-discounts {
					width: 100%;
					font-size: 24rpx;
					align-items: center;
					line-height: 50rpx;
					display: flex;

					.discounts-type {
						display: inline-block;
						// border: 1rpx solid $red;
						border-radius: 4rpx;
						padding: 4rpx 8rpx;
						margin-right: 10rpx;
						 color: #EA655E;
						font-size: 22rpx;
						min-width: 70rpx;
						text-align: center;
						// background: linear-gradient(151deg, #F69E97 0%, #EA655E 100%);
						border:2rpx solid #F69E97;
						
					}

					.discounts-detail {
						color: #2a2a2a;
					}
				}

				.item-price {
					position: absolute;
					bottom: 6rpx;
					left: 0;
					color: $red;
					font-size: 32rpx;
				}

				&.text-gray {

					.item-name,
					.item-price {
						color: #aaa
					}

					.item-discounts {
						.discounts-type {
							border: 1rpx solid #aaa;
						}

						.discounts-type,
						.discounts-detail {
							color: #aaa
						}
					}
				}
			}
		}

		.item-btns {
			width: 100%;
			padding: 20rpx 32rpx;
			display: flex;
			flex-direction: row-reverse;
		}

	}

	.mix-empty {
		height: 100vh;
	}
</style>
